package game01;

public class Tank {
    public static final int DIRECTION_UP = 0;
    public static final int DIRECTION_DOWN = 1;
    public static final int DIRECTION_LEFT = 2;
    public static final int DIRECTION_RIGHT = 3;
    // x坐标
    private int x;
    // y坐标
    private int y;
    // 颜色
    private Color color;
    // 方向
    private int direction;

    public Tank(){}

    public Tank(int x, int y,Color color) {
        this.x = x;
        this.y = y;
        this.color = color;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public int getDirection() {
        return direction;
    }public void setDirection(int direction) {
        this.direction = direction;
    }

    public void draw(Graphics g){
        g.setColor(color);
        switch (direction){
            case DIRECTION_UP:
                //左履带
                g.fill3DRect(x,y,10,60,false);
                //车体
                g.fill3DRect(x + 10,y + 5,30,50,false);
                //右履带
                g.fill3DRect(x + 10 + 30, y, 10,60,false);
                //炮塔
                g.fillOval(x + 10,y + 5 + 10,30,30);
                //炮管
                g.fillRect(x + 10 + 15 - 3,y,6,15);
                break;
            case DIRECTION_DOWN:
                //左履带
                g.fill3DRect(x,y,10,60,false);
                //车体
                g.fill3DRect(x + 10,y + 5,30,50,false);
                //右履带
                g.fill3DRect(x + 10 + 30, y, 10,60,false);
                //炮塔
                g.fillOval(x + 10,y + 5 + 10,30,30);
                //炮管
                g.fillRect(x + 10 + 15 - 3,y + 5 + 10 + 30 + 1,6,15);
                break;
            case DIRECTION_LEFT:
                //右履带
                g.fill3DRect(x , y, 60,10,false);
                //车体
                g.fill3DRect(x + 5,y + 10,50,30,false);
                //左履带
                g.fill3DRect(x , y + 10 + 30, 60,10,false);
                //炮塔
                g.fillOval(x + 5 + 10,y + 10,30,30);
                //炮管
                g.fillRect(x,y + 10 + 15 - 3,15,6);
                break;
            case DIRECTION_RIGHT:
                //右履带
                g.fill3DRect(x , y, 60,10,false);
                //车体
                g.fill3DRect(x + 5,y + 10,50,30,false);
                //左履带
                g.fill3DRect(x , y + 10 + 30, 60,10,false);
                //炮塔
                g.fillOval(x + 5 + 10,y + 10,30,30);
                //炮管
                g.fillRect(x + 5 + 10 + 30 + 1,y + 10 + 15 - 3,15,6);
                break;
        }

    }
}

